/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DBTables;

import DBManager.*;
import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.ParameterMetaData;
import java.sql.SQLException;

/**
 *Класс таблицы RB_Of_Events
 * @author Иван
 */
public class TReferanceBookOfEvents extends DataManager {

    public String Id_UserFK;
    public String Id_MessageFK;

    public TReferanceBookOfEvents(Connection conn, String tableName) throws SQLException {
        super(conn, tableName);

        SelectPrepStatement = connection.prepareStatement("select * from " + TableName);
        InsertPrepStatement = connection.prepareStatement("insert into " + TableName + "(Id_User, Id_Message) values (?,?) ");
        UpdatePrepStatement = connection.prepareStatement("update " + TableName + " (Id_User = ? , Id_Message = ?) Where Id_RBOfEvents = ? ");
        DeletePrepStatement = connection.prepareStatement("delete from" + TableName + " Where Id_RBOfEvents = ?");
    }

    @Override
    public void SetValues(PreparedStatement prepareStatement) throws SQLException {

        ParameterMetaData metaData = prepareStatement.getParameterMetaData();
        int countParameters = metaData.getParameterCount();

        if (countParameters >= 2) // for insert prepared statement
        {
            prepareStatement.setString(1, Id_UserFK);
            prepareStatement.setString(2, Id_MessageFK);

        }

        if ((countParameters == 3))// for update prepared statement
        {
            prepareStatement.setString(3, ID_Table);
        }

        if ((countParameters == 1))// for delete prepared statement
        {
            prepareStatement.setString(1, ID_Table);
        }
    }
}
